<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="Kate, the KDE Advanced Text Editor" />
<title>door.ss</title>
</head>
<body>
<pre>
<span style="color: #000000;">#lang scheme</span>
<span style="font-style: italic;color: #808080;">;GNU  Klub RFID door control program  </span>
<span style="font-style: italic;color: #808080;">;  Copyright  (C) 2009,  hepek</span>
<span style="font-style: italic;color: #808080;">;  (http://gnu.elfak.ni.ac.yu) gnuklub [at] gmail [dot] com</span>
<span style="font-style: italic;color: #808080;">;  </span>
<span style="font-style: italic;color: #808080;">;  This program is free software: you can redistribute it and/or modify</span>
<span style="font-style: italic;color: #808080;">;  it under the terms of the GNU General Public License as published by</span>
<span style="font-style: italic;color: #808080;">;  the Free Software Foundation, either version 3 of the License, or</span>
<span style="font-style: italic;color: #808080;">;  (at your option) any later version.</span>
<span style="font-style: italic;color: #808080;">;</span>
<span style="font-style: italic;color: #808080;">;  This program is distributed in the hope that it will be useful,</span>
<span style="font-style: italic;color: #808080;">;  but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="font-style: italic;color: #808080;">;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="font-style: italic;color: #808080;">;  GNU General Public License for more details.</span>
<span style="font-style: italic;color: #808080;">;  </span>
<span style="font-style: italic;color: #808080;">;  You should have received a copy of the GNU General Public License</span>
<span style="font-style: italic;color: #808080;">;  along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>


<span style="font-style: italic;color: #808080;">;   ;;; ;;; ;;;          ;;;                                              </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;  ;;;          ;;;                                              </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;; ;;;;;;    ;;;;;;   ;;;;;    ;;;;;   ;;;;;      ;;;;    ;;;;;  </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;; ;;;;;;;  ;;;;;;;  ;;;;;;;  ;;;;;;;  ;;;;;     ;; ;;;  ;;;;;;; </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;; ;;;  ;;  ;;  ;;;  ;;   ;;  ;;   ;;  ;;;       ;;;     ;;   ;; </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;; ;;;  ;; ;;;  ;;;  ;;   ;;  ;;   ;;  ;;;       ;;;;;;  ;;   ;; </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;; ;;;  ;;  ;;  ;;;  ;;   ;;  ;;   ;;  ;;;   ;;      ;;; ;;   ;; </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;; ;;;;;;;  ;;;;;;;  ;;;;;;;  ;;;;;;;  ;;;   ;;; ;;; ;;; ;;;;;;; </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;; ;; ;;;    ;;;;;;   ;;;;;    ;;;;;   ;;;   ;;; ;;;;;;   ;;;;;  </span>
<span style="font-style: italic;color: #808080;">; here are some functions written in C used mainly to access hardware</span>

<span style="font-weight: bold;color: #ff0000;">(</span><span style="color: #000000;">require scheme/foreign</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="color: #000000;">unsafe!</span><span style="font-weight: bold;color: #ff0000;">)</span><span style="color: #000000;"> </span><span style="font-style: italic;color: #808080;">;imported functions may crash the app</span>

<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> door </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">ffi-lib </span><span style="color: #dd0000;">"./libdoor"</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>

<span style="font-style: italic;color: #808080;">;opens the door (door/open fd seconds)</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> door/open</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">get-ffi-obj </span><span style="color: #dd0000;">"door_open"</span><span style="color: #000000;"> door </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">_fun _int _int -&gt; _int</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-style: italic;color: #808080;">;closes the door (door/close fd)</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> door/close</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">get-ffi-obj </span><span style="color: #dd0000;">"door_close"</span><span style="color: #000000;"> door </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">_fun _int -&gt; _int</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-style: italic;color: #808080;">;initializes serial interface (door/init devName)</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> door/init </span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">get-ffi-obj </span><span style="color: #dd0000;">"serial_init"</span><span style="color: #000000;"> door </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">_fun _string  -&gt; _int</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-style: italic;color: #808080;">;resets serial inteface</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> door/reset</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">get-ffi-obj </span><span style="color: #dd0000;">"serial_reset"</span><span style="color: #000000;"> door </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">_fun _int _string -&gt; _int</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> door/readln</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">get-ffi-obj </span><span style="color: #dd0000;">"serial_readln_scheme"</span><span style="color: #000000;"> door </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">_fun _int -&gt; _string</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>

<span style="font-style: italic;color: #808080;">;some test functions: to be deleted</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> door/test</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">get-ffi-obj </span><span style="color: #dd0000;">"door_test"</span><span style="color: #000000;"> door </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">_fun _int -&gt; _int</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> door/str</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">get-ffi-obj </span><span style="color: #dd0000;">"door_string"</span><span style="color: #000000;"> door </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">_fun _string _int -&gt; _string</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>

<span style="font-style: italic;color: #808080;">;                               ;;                  ;;;</span>
<span style="font-style: italic;color: #808080;">;                              ;;;                  ;;;</span>
<span style="font-style: italic;color: #808080;">;    ;;;;;    ;;;;;   ;; ;;;  ;;;;;; ;;;;;  ;;;;;   ;;;</span>
<span style="font-style: italic;color: #808080;">;   ;;;;;;;  ;;;;;;;  ;;;;;;; ;;;;;  ;;;;; ;;;;;;;  ;;;</span>
<span style="font-style: italic;color: #808080;">;   ;;   ;   ;;   ;;  ;;; ;;;  ;;;   ;;;   ;;   ;;  ;;;</span>
<span style="font-style: italic;color: #808080;">;   ;;       ;;   ;;  ;;  ;;;  ;;;   ;;;   ;;   ;;  ;;;</span>
<span style="font-style: italic;color: #808080;">;   ;;   ;;  ;;   ;;  ;;  ;;;  ;;;   ;;;   ;;   ;;  ;;;</span>
<span style="font-style: italic;color: #808080;">;   ;;;;;;;  ;;;;;;;  ;;  ;;;  ;;;;  ;;;   ;;;;;;;  ;;;</span>
<span style="font-style: italic;color: #808080;">;    ;;;;;    ;;;;;   ;;  ;;;   ;;;  ;;;    ;;;;;   ;;;</span>
<span style="font-style: italic;color: #808080;">;                                                      </span>
<span style="font-style: italic;color: #808080;">; functions that communicate with hardware. main function lurch opens the door.</span>

<span style="font-weight: bold;color: #ff0000;">(</span><span style="color: #000000;">require scheme/date</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-style: italic;color: #808080;">;TODO: try load, start! or something else. loading user hash table</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> conf </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="font-weight: bold;color: #000000;">open-input-file</span><span style="color: #000000;"> </span><span style="color: #dd0000;">"./users.ss"</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> *users* </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="font-weight: bold;color: #000000;">read</span><span style="color: #000000;"> conf</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #000000;">close-input-port</span><span style="color: #000000;"> conf</span><span style="font-weight: bold;color: #ff0000;">)</span>

<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">time-formatted</span><span style="font-weight: bold;color: #ff8800;">)</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="font-weight: bold;color: #000000;">let</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">[date </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">seconds-&gt;date </span><span style="font-weight: bold;color: #000088;">(</span><span style="color: #000000;">current-seconds</span><span style="font-weight: bold;color: #000088;">)</span><span style="font-weight: bold;color: #008800;">)</span><span style="color: #000000;">]</span><span style="font-weight: bold;color: #888800;">)</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">format </span><span style="color: #dd0000;">"~a-~a-~a-~a:~a:~a"</span><span style="color: #000000;"> </span>
<span style="color: #000000;">            </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">date-year date</span><span style="font-weight: bold;color: #008800;">)</span>
<span style="color: #000000;">            </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">date-month date</span><span style="font-weight: bold;color: #008800;">)</span>
<span style="color: #000000;">            </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">date-day date</span><span style="font-weight: bold;color: #008800;">)</span>
<span style="color: #000000;">            </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">date-hour date</span><span style="font-weight: bold;color: #008800;">)</span>
<span style="color: #000000;">            </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">date-minute date</span><span style="font-weight: bold;color: #008800;">)</span>
<span style="color: #000000;">            </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">date-second date</span><span style="font-weight: bold;color: #008800;">)</span>
<span style="color: #000000;">            </span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>

<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">current-hour</span><span style="font-weight: bold;color: #ff8800;">)</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="font-weight: bold;color: #000000;">let</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">[date </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">seconds-&gt;date </span><span style="font-weight: bold;color: #000088;">(</span><span style="color: #000000;">current-seconds</span><span style="font-weight: bold;color: #000088;">)</span><span style="font-weight: bold;color: #008800;">)</span><span style="color: #000000;">]</span><span style="font-weight: bold;color: #888800;">)</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">date-hour date</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>

<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">current-day</span><span style="font-weight: bold;color: #ff8800;">)</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="font-weight: bold;color: #000000;">let</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">[date </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">seconds-&gt;date </span><span style="font-weight: bold;color: #000088;">(</span><span style="color: #000000;">current-seconds</span><span style="font-weight: bold;color: #000088;">)</span><span style="font-weight: bold;color: #008800;">)</span><span style="color: #000000;">]</span><span style="font-weight: bold;color: #888800;">)</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">date-week-day date</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-style: italic;color: #808080;">;range can be a cons denoting interval or a list of accepted values</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">in-range range number</span><span style="font-weight: bold;color: #ff8800;">)</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="font-weight: bold;color: #000000;">cond</span>
<span style="color: #000000;">    [</span><span style="font-weight: bold;color: #888800;">(</span><span style="font-weight: bold;color: #000000;">and</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #008800;">(</span><span style="font-weight: bold;color: #000000;">list?</span><span style="color: #000000;"> range</span><span style="font-weight: bold;color: #008800;">)</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #008800;">(</span><span style="font-weight: bold;color: #000000;">number?</span><span style="color: #000000;"> number</span><span style="font-weight: bold;color: #008800;">)</span><span style="font-weight: bold;color: #888800;">)</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">ormap </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">λ </span><span style="font-weight: bold;color: #000088;">(</span><span style="color: #000000;">x</span><span style="font-weight: bold;color: #000088;">)</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #000088;">(</span><span style="font-weight: bold;color: #d22811;">=</span><span style="color: #000000;"> x number</span><span style="font-weight: bold;color: #000088;">)</span><span style="font-weight: bold;color: #008800;">)</span><span style="color: #000000;"> range</span><span style="font-weight: bold;color: #888800;">)</span><span style="color: #000000;">]</span>
<span style="color: #000000;">    [</span><span style="font-weight: bold;color: #888800;">(</span><span style="font-weight: bold;color: #000000;">and</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #008800;">(</span><span style="font-weight: bold;color: #000000;">pair?</span><span style="color: #000000;"> range</span><span style="font-weight: bold;color: #008800;">)</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #008800;">(</span><span style="font-weight: bold;color: #000000;">number?</span><span style="color: #000000;"> number</span><span style="font-weight: bold;color: #008800;">)</span><span style="font-weight: bold;color: #888800;">)</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #888800;">(</span><span style="font-weight: bold;color: #000000;">and</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #008800;">(</span><span style="font-weight: bold;color: #d22811;">&gt;</span><span style="color: #000000;"> number </span><span style="font-weight: bold;color: #000088;">(</span><span style="font-weight: bold;color: #000000;">car</span><span style="color: #000000;"> range</span><span style="font-weight: bold;color: #000088;">)</span><span style="font-weight: bold;color: #008800;">)</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #008800;">(</span><span style="font-weight: bold;color: #d22811;">&lt;</span><span style="color: #000000;"> number </span><span style="font-weight: bold;color: #000088;">(</span><span style="font-weight: bold;color: #000000;">cdr</span><span style="color: #000000;"> range</span><span style="font-weight: bold;color: #000088;">)</span><span style="font-weight: bold;color: #008800;">)</span><span style="font-weight: bold;color: #888800;">)</span><span style="color: #000000;">]</span>
<span style="color: #000000;">    [</span><span style="font-weight: bold;color: #000000;">else</span><span style="color: #000000;"> </span><span style="color: #0000ff;">#f</span><span style="color: #000000;">]</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>

<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">lurch fd</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="color: #000000;"> </span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="font-weight: bold;color: #000000;">let</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">[message </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">thread-receive</span><span style="font-weight: bold;color: #008800;">)</span><span style="color: #000000;">]</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-style: italic;color: #808080;">;this line will block and wait</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #888800;">(</span><span style="font-weight: bold;color: #000000;">if</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">regexp-match #rx</span><span style="color: #dd0000;">"^RFID.*|WEB.*"</span><span style="color: #000000;"> message</span><span style="font-weight: bold;color: #008800;">)</span>
<span style="color: #000000;">        </span><span style="font-weight: bold;color: #008800;">(</span><span style="font-weight: bold;color: #000000;">let</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #000088;">(</span><span style="color: #000000;">[reply </span><span style="font-weight: bold;color: #880088;">(</span><span style="color: #000000;">door/open fd </span><span style="color: #0000ff;">2</span><span style="font-weight: bold;color: #880088;">)</span><span style="color: #000000;">]</span><span style="font-weight: bold;color: #000088;">)</span>
<span style="color: #000000;">          </span><span style="font-weight: bold;color: #000088;">(</span><span style="font-weight: bold;color: #000000;">cond</span>
<span style="color: #000000;">            [</span><span style="font-weight: bold;color: #880088;">(</span><span style="font-weight: bold;color: #000000;">eq?</span><span style="color: #000000;"> reply </span><span style="color: #0000ff;">0</span><span style="font-weight: bold;color: #880088;">)</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #880088;">(</span><span style="color: #000000;">log-warning </span><span style="font-weight: bold;color: #ff0000;">(</span><span style="color: #000000;">format </span><span style="color: #dd0000;">"OPENED at ~a by ~a"</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">time-formatted</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="color: #000000;"> message</span><span style="font-weight: bold;color: #ff0000;">)</span><span style="font-weight: bold;color: #880088;">)</span><span style="color: #000000;">]</span>
<span style="color: #000000;">            [</span><span style="font-weight: bold;color: #000000;">else</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #880088;">(</span><span style="color: #000000;">log-warning </span><span style="font-weight: bold;color: #ff0000;">(</span><span style="color: #000000;">format </span><span style="color: #dd0000;">"\tERROR[~a] opening at ~a for ~a"</span><span style="color: #000000;"> reply </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">time-formatted</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="color: #000000;"> message</span><span style="font-weight: bold;color: #ff0000;">)</span><span style="font-weight: bold;color: #880088;">)</span>
<span style="color: #000000;">                  </span><span style="font-weight: bold;color: #880088;">(</span><span style="color: #000000;">set! fd </span><span style="font-weight: bold;color: #ff0000;">(</span><span style="color: #000000;">door/reset devName</span><span style="font-weight: bold;color: #ff0000;">)</span><span style="font-weight: bold;color: #880088;">)</span><span style="color: #000000;"> </span><span style="font-style: italic;color: #808080;">;on error reset the device</span>
<span style="color: #000000;">                  ]</span><span style="font-weight: bold;color: #000088;">)</span><span style="font-weight: bold;color: #008800;">)</span><span style="color: #000000;"> </span>
<span style="color: #000000;">        </span><span style="color: #0000ff;">#f</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="color: #000000;">  </span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">lurch fd</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>

<span style="font-style: italic;color: #808080;">;                                     </span>
<span style="font-style: italic;color: #808080;">;                         ;;;         </span>
<span style="font-style: italic;color: #808080;">;                         ;;          </span>
<span style="font-style: italic;color: #808080;">;   ;; ;;;  ;;;   ;;;;;   ;;; ;; ;;;  </span>
<span style="font-style: italic;color: #808080;">;   ;;;;;;;;;;;  ;;;;;;;  ;;; ;;;;;;; </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;;  ;;;     ;;;  ;;; ;;; ;;; </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;;  ;;;  ;;;;;;  ;;; ;;  ;;; </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;;  ;;; ;;;  ;;  ;;; ;;  ;;; </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;;  ;;; ;;; ;;;  ;;; ;;  ;;; </span>
<span style="font-style: italic;color: #808080;">;   ;;; ;;;  ;;; ;;;; ;;  ;;; ;;  ;;; </span>

<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">say-text message</span><span style="font-weight: bold;color: #ff8800;">)</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="font-weight: bold;color: #000000;">call-with-output-file</span><span style="color: #000000;"> </span><span style="color: #dd0000;">"festival-say.txt"</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">λ </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">file</span><span style="font-weight: bold;color: #008800;">)</span>
<span style="color: #000000;">                                              </span><span style="font-weight: bold;color: #008800;">(</span><span style="font-weight: bold;color: #000000;">write</span><span style="color: #000000;"> `</span><span style="font-weight: bold;color: #000088;">(</span><span style="color: #000000;">SayText ,message</span><span style="font-weight: bold;color: #000088;">)</span><span style="color: #000000;"> file</span><span style="font-weight: bold;color: #008800;">)</span><span style="font-weight: bold;color: #888800;">)</span><span style="color: #000000;"> #:exists 'append</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>

<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">RFID-authenticate-and-open </span><span style="font-weight: bold;color: #000000;">read</span><span style="font-weight: bold;color: #ff8800;">)</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="font-weight: bold;color: #000000;">let</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">[user-data </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">hash-ref *users* </span><span style="font-weight: bold;color: #000000;">read</span><span style="color: #000000;"> </span><span style="color: #0000ff;">#f</span><span style="font-weight: bold;color: #008800;">)</span><span style="color: #000000;">]</span><span style="font-weight: bold;color: #888800;">)</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #888800;">(</span><span style="font-weight: bold;color: #000000;">if</span><span style="color: #000000;"> user-data</span>
<span style="color: #000000;">        </span><span style="font-weight: bold;color: #008800;">(</span><span style="font-weight: bold;color: #000000;">cond</span>
<span style="color: #000000;">          [</span><span style="font-weight: bold;color: #000088;">(</span><span style="font-weight: bold;color: #000000;">and</span><span style="color: #000000;"> </span>
<span style="color: #000000;">            </span><span style="font-weight: bold;color: #880088;">(</span><span style="color: #000000;">in-range </span><span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #000000;">caadr</span><span style="color: #000000;"> user-data</span><span style="font-weight: bold;color: #ff0000;">)</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #ff0000;">(</span><span style="color: #000000;">current-hour</span><span style="font-weight: bold;color: #ff0000;">)</span><span style="font-weight: bold;color: #880088;">)</span><span style="color: #000000;"> </span>
<span style="color: #000000;">            </span><span style="font-weight: bold;color: #880088;">(</span><span style="color: #000000;">in-range </span><span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #000000;">cadadr</span><span style="color: #000000;"> user-data</span><span style="font-weight: bold;color: #ff0000;">)</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #ff0000;">(</span><span style="color: #000000;">current-day</span><span style="font-weight: bold;color: #ff0000;">)</span><span style="font-weight: bold;color: #880088;">)</span><span style="font-weight: bold;color: #000088;">)</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #000088;">(</span><span style="color: #000000;">thread-send to-lurch </span><span style="font-weight: bold;color: #880088;">(</span><span style="font-weight: bold;color: #000000;">string-append</span><span style="color: #000000;"> </span><span style="color: #dd0000;">"RFID: "</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #000000;">car</span><span style="color: #000000;"> user-data</span><span style="font-weight: bold;color: #ff0000;">)</span><span style="font-weight: bold;color: #880088;">)</span><span style="font-weight: bold;color: #000088;">)</span>
<span style="color: #000000;">                                                         </span><span style="font-weight: bold;color: #000088;">(</span><span style="font-weight: bold;color: #000000;">string-append</span><span style="color: #000000;"> </span><span style="color: #dd0000;">"Welcome, "</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #880088;">(</span><span style="font-weight: bold;color: #000000;">car</span><span style="color: #000000;"> user-data</span><span style="font-weight: bold;color: #880088;">)</span><span style="color: #000000;"> </span><span style="color: #dd0000;">"."</span><span style="font-weight: bold;color: #000088;">)</span><span style="color: #000000;">]</span>
<span style="color: #000000;">          [</span><span style="font-weight: bold;color: #000000;">else</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #000088;">(</span><span style="font-weight: bold;color: #000000;">string-append</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #880088;">(</span><span style="font-weight: bold;color: #000000;">car</span><span style="color: #000000;"> user-data</span><span style="font-weight: bold;color: #880088;">)</span><span style="color: #000000;"> </span><span style="color: #dd0000;">", please try later!"</span><span style="font-weight: bold;color: #000088;">)</span><span style="color: #000000;">]</span><span style="font-weight: bold;color: #008800;">)</span>
<span style="color: #000000;">        </span><span style="color: #dd0000;">"Access denied!"</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>

<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">listener</span><span style="font-weight: bold;color: #ff8800;">)</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="font-weight: bold;color: #000000;">let</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">[textID </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">regexp-match #rx</span><span style="color: #dd0000;">"^[0|1]+"</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #000088;">(</span><span style="color: #000000;">door/readln fd</span><span style="font-weight: bold;color: #000088;">)</span><span style="font-weight: bold;color: #008800;">)</span><span style="color: #000000;">]</span><span style="font-weight: bold;color: #888800;">)</span>
<span style="color: #000000;">    </span><span style="font-weight: bold;color: #888800;">(</span><span style="font-weight: bold;color: #000000;">if</span><span style="color: #000000;"> textID</span>
<span style="color: #000000;">        </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">say-text </span><span style="font-weight: bold;color: #000088;">(</span><span style="color: #000000;">RFID-authenticate-and-open </span><span style="font-weight: bold;color: #880088;">(</span><span style="font-weight: bold;color: #000000;">car</span><span style="color: #000000;"> textID</span><span style="font-weight: bold;color: #880088;">)</span><span style="font-weight: bold;color: #000088;">)</span><span style="font-weight: bold;color: #008800;">)</span>
<span style="color: #000000;">        </span><span style="color: #0000ff;">#f</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">sleep </span><span style="color: #0000ff;">2</span><span style="font-weight: bold;color: #ff8800;">)</span>
<span style="color: #000000;">  </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">listener</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-style: italic;color: #808080;">;                         ;;;          ;;;            ;;;;;;;                          </span>
<span style="font-style: italic;color: #808080;">;                         ;;;          ;;;           ;;;; ;;                           </span>
<span style="font-style: italic;color: #808080;">;    ;;;;;   ;; ;;;    ;;;;;;       ;;;;;;   ;;;;;  ;;;;; ;;; ;; ;;;    ;;;;;    ;;;;  </span>
<span style="font-style: italic;color: #808080;">;   ;;;;;;;  ;;;;;;;  ;;;;;;;      ;;;;;;;  ;;;;;;; ;;;;; ;;; ;;;;;;;  ;;;;;;;  ;; ;;; </span>
<span style="font-style: italic;color: #808080;">;   ;;   ;;  ;;; ;;;  ;;  ;;;      ;;  ;;;  ;;   ;;  ;;;  ;;; ;;; ;;;  ;;   ;;  ;;;    </span>
<span style="font-style: italic;color: #808080;">;  ;;;;;;;;; ;;  ;;; ;;;  ;;;     ;;;  ;;; ;;;;;;;;; ;;;  ;;; ;;  ;;; ;;;;;;;;; ;;;;;; </span>
<span style="font-style: italic;color: #808080;">;   ;;       ;;  ;;;  ;;  ;;;      ;;  ;;;  ;;       ;;;  ;;; ;;  ;;;  ;;           ;;;</span>
<span style="font-style: italic;color: #808080;">;   ;;;;;;;  ;;  ;;;  ;;;;;;;      ;;;;;;;  ;;;;;;;  ;;;  ;;; ;;  ;;;  ;;;;;;;  ;;; ;;;</span>
<span style="font-style: italic;color: #808080;">;    ;;;;;   ;;  ;;;   ;;;;;;       ;;;;;;   ;;;;;   ;;;  ;;; ;;  ;;;   ;;;;;   ;;;;;; </span>

<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> devName </span><span style="color: #dd0000;">"/dev/ttyS0"</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> fd </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">door/init devName</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-style: italic;color: #808080;">;(define fd 1); from stdin </span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="font-weight: bold;color: #d22811;">define</span><span style="color: #000080;"> to-lurch </span><span style="font-weight: bold;color: #ff8800;">(</span><span style="color: #000000;">thread </span><span style="font-weight: bold;color: #888800;">(</span><span style="color: #000000;">λ </span><span style="font-weight: bold;color: #008800;">()</span><span style="color: #000000;"> </span><span style="font-weight: bold;color: #008800;">(</span><span style="color: #000000;">lurch fd</span><span style="font-weight: bold;color: #008800;">)</span><span style="font-weight: bold;color: #888800;">)</span><span style="font-weight: bold;color: #ff8800;">)</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="font-weight: bold;color: #ff0000;">(</span><span style="color: #000000;">listener</span><span style="font-weight: bold;color: #ff0000;">)</span>
<span style="color: #000000;">  </span><span style="font-style: italic;color: #808080;">;(say-text (RFID-authenticate-and-open "01"))</span>
<span style="color: #000000;">  </span>
<span style="color: #000000;">  </span></pre></body>
</html>
